package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BorrowMoneyen;
import com.ruoyi.system.service.IBorrowMoneyenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户借款Controller
 *
 * @author ruoyi
 * @date 2021-05-07
 */
@RestController
@RequestMapping("/system/moneyen")
public class BorrowMoneyenController extends BaseController
{
    @Autowired
    private IBorrowMoneyenService borrowMoneyenService;

    /**
     * 查询用户借款列表
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:list')")
    @GetMapping("/list")
    public TableDataInfo list(BorrowMoneyen borrowMoneyen)
    {
        startPage();
        List<BorrowMoneyen> list = borrowMoneyenService.selectBorrowMoneyenList(borrowMoneyen);
        return getDataTable(list);
    }

    /**
     * 导出用户借款列表
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:export')")
    @Log(title = "用户借款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BorrowMoneyen borrowMoneyen)
    {
        List<BorrowMoneyen> list = borrowMoneyenService.selectBorrowMoneyenList(borrowMoneyen);
        ExcelUtil<BorrowMoneyen> util = new ExcelUtil<BorrowMoneyen>(BorrowMoneyen.class);
        return util.exportExcel(list, "moneyen");
    }

    /**
     * 获取用户借款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:query')")
    @GetMapping(value = "/{borrowId}")
    public AjaxResult getInfo(@PathVariable("borrowId") Long borrowId)
    {
        return AjaxResult.success(borrowMoneyenService.selectBorrowMoneyenById(borrowId));
    }

    /**
     * 新增用户借款
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:add')")
    @Log(title = "用户借款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BorrowMoneyen borrowMoneyen)
    {
        return toAjax(borrowMoneyenService.insertBorrowMoneyen(borrowMoneyen));
    }

    /**
     * 修改用户借款
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:edit')")
    @Log(title = "用户借款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BorrowMoneyen borrowMoneyen)
    {
        return toAjax(borrowMoneyenService.updateBorrowMoneyen(borrowMoneyen));
    }

    /**
     * 删除用户借款
     */
    @PreAuthorize("@ss.hasPermi('system:moneyen:remove')")
    @Log(title = "用户借款", businessType = BusinessType.DELETE)
    @DeleteMapping("/{borrowIds}")
    public AjaxResult remove(@PathVariable Long[] borrowIds)
    {
        return toAjax(borrowMoneyenService.deleteBorrowMoneyenByIds(borrowIds));
    }
}